import 'package:dio/dio.dart';
import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';

/// @Author  leijingxing
/// @Date  2023/4/4 11:29
/// @LastEditTime: 2023/4/4 11:29
/// @LastEditors: leijingxing
/// @Description: 上传文件接口
abstract class FileUploadApis {
  /// 上传文件
  /// @param fileUrl 文件路径
  /// @param fileName 文件名
  static Future<String> uploadFile({required String fileUrl, String? fileName}) async {
    final formData = FormData.fromMap({
      'file': await MultipartFile.fromFile(fileUrl, filename: fileName),
    });
    final res = await HttpUtil()
        .generatePostRequest(Interface.uploadUrl, data: formData)
        .execute();
    if (res.data != null) {
      if (res.data['url'] != null) {
        return '${res.data['url']}';
      } else {
        return '';
      }
    } else {
      return '';
    }
  }
}
